// OGoMojo
// Whitemice.MOGI.RPC2.Team
// License: LGPL
// Copyright: Whitemice Consulting, 2006
// Author(s): Adam Tauno Williams (awilliam@whitemice.org)
using CookComputing.XmlRpc;
using Whitemice.MOGI;
using System;
using System.Collections;

namespace Whitemice.MOGI.RPC2 {
	/// \brief Implementation of ITeam
	public class Team : Whitemice.MOGI.RPC2.Document, ITeam {
		protected ArrayList	members;
	
		/// \brief Constructor
		/// \param document An XmlRpcStruct document
		/// \param server Reference to server object	
		public Team (XmlRpcStruct document, Server server)
		 : base(document, server) 
		{
		 	members = new ArrayList();	
		}
		
		/// \brief Provides the unique name of the object
		public override string Name 
		{
			get 
			{
				string name;
				
				name = null;
				if (document.ContainsKey("id"))
					name = ("Document/Team/" + document["id"].ToString().Substring(
						document["id"].ToString().LastIndexOf('/') + 1));
					else if (document.ContainsKey("companyId"))
							name = ("Document/Team/" + document["companyId"].ToString());
				if (name == null)
					Log.Debug("Name == null (Team document does not contain an id or companyId element)");
					else Log.Debug("Name == " + name);
				return name;
			}
		}
		
		/// \brief Accessor for the description value
		public string Description {
			get {
				return this.document["description"].ToString();
			}
		}

		/// \brief Accessor for the email value
		public string EMail {
			get {
				if (this.document.ContainsKey("email"))
					return this.document["email"].ToString();
					else return "";
			}
		}

		/// \brief Accessor for the isLocationTeam value
		public bool Location {
			get {
				if (this.document.ContainsKey("isLocationTeam"))
					if (this.document["isLocationTeam"].ToString() == "1")
						return true;
						else return false;
					else return false;
			}
		}
		
		/// \brief Accessor for the number value
		public override string Number {
			get {
				return this.document["number"].ToString();
			}
		}
		
		public ArrayList Members
		{
			get { return members;}
			set { SetMembers(value); }
		}
		
		internal void SetMembers(ArrayList members)
		{
			this.members = members;
		}
	}
}